import axios from "axios";

// alert(process.env.NODE_ENV);

import { getConfig, getJWTConfig } from "./services/apiConfig";
const { API_KEY, BASE_URL } = getApiConfig();
// const { JWT, BASE_URL } = getJWTConfig();
const JWT = "";
const myAxios_JWT = axios.create({
  // 区分开发和线上环境
  baseURL: BASE_URL,
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${JWT}`,
  },
});

// // Add a request interceptor
// myAxios.interceptors.request.use(
//   function (config) {
//     // Do something before request is sent
//     return config;
//   },
//   function (error) {
//     // Do something with request error
//     return Promise.reject(error);
//   }
// );

// // Add a response interceptor
// myAxios.interceptors.response.use(
//   function (response) {
//     // Any status code that lie within the range of 2xx cause this function to trigger
//     // Do something with response data
//     console.log(response);

//     const { data } = response;
//     console.log(data);
//     // 未登录
//     if (data.code === 40100) {
//       // 不是获取用户信息接口，或者不是登录页面，则跳转到登录页面
//       if (
//         !response.request.responseURL.includes("user/current") &&
//         !window.location.pathname.includes("/user/login")
//       ) {
//         window.location.href = `/user/login?redirect=${window.location.href}`;
//       }
//     }
//     return response;
//   },
//   function (error) {
//     // Any status codes that falls outside the range of 2xx cause this function to trigger
//     // Do something with response error
//     return Promise.reject(error);
//   }
// );

export default myAxios_JWT;
